package com.xiaoshuaila.filter;

import com.mysql.cj.Session;
import com.xiaoshuaila.settings.domain.user;

import javax.servlet.*;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
import java.io.IOException;

public class loginfilter implements Filter {
    @Override
    public void doFilter(ServletRequest request,
                         ServletResponse response,
                         FilterChain filterChain) throws IOException, ServletException {
        System.out.println("登录过滤器");
        HttpServletRequest Request= (HttpServletRequest) request;
        HttpServletResponse Response= (HttpServletResponse) response;
        HttpSession session=Request.getSession();
        user user= (user) session.getAttribute("user");
        System.out.println(user);
        System.out.println(Request.getServletPath());
        if (user!=null
                ||("/setting/user/save.do").equals(Request.getServletPath())
                ||("/login.jsp").equals(Request.getServletPath()))
        {
            System.out.println("通过");
            filterChain.doFilter(request,response);
        }
        else Response.sendRedirect(Request.getContextPath()+"/login.jsp");
    }
}